package springboot.controller;

import org.redisson.RedissonLock;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author zhangxin
 * @date 2021/4/29
 */
@RestController
public class RedisLockController {

    @Resource
    private RedissonClient redissonClient;

    @GetMapping("/lock")
    public String lock() {

        RLock lock = redissonClient.getLock("java");

        try {
            lock.lock();


        } finally {
            lock.unlock();
        }
        return "oK";

    }
}